﻿namespace Refract.Utility
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    public class Pair
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Pair"/> class.
        /// </summary>
        /// <param name="first">The first.</param>
        /// <param name="second">The second.</param>
        public Pair(object first, object second)
        {
            First = first;
            Second = second;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets or sets the first value of a pair.
        /// </summary>
        /// <value>The first.</value>
        public object First
        {
            get; set;
        }

        /// <summary>
        /// Gets or sets the second.
        /// </summary>
        /// <value>The second.</value>
        public object Second
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Gets the first typed value of a pair.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetFirst<T>()
        {
            if (!(First is T)) throw new InvalidCastException(Second.GetType().Name + " First cannot be cast to" + typeof(T).Name);
            return (T) First;
        }

        /// <summary>
        /// Gets the second typed value of a pair.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetSecond<T>()
        {
            if(!(Second is T)) throw new InvalidCastException(Second.GetType().Name + " Second cannot be cast to" + typeof(T).Name );
            return (T)Second;
        }

        #endregion Methods
    }
}